package com.hzcc.hzccblog.module.controller;

import com.hzcc.hzccblog.common.Result;
import com.hzcc.hzccblog.module.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author 早睡蛋
 * @Date 2022/6/20 16:00:26
 * @Desc:
 */
@RestController
@RequestMapping("api/admin")
@CrossOrigin
@Slf4j
@Api(tags = "管理员相关")
public class AdminController {

    @Value("${myAvator.dir}")
    private String myAvator;

    @Autowired
    private AdminService adminService;

    /**
     * 获取头像
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = Result.class),
    })
    @ApiOperation("获取头像")
    @PostMapping("/getAvator")
    public Result getAvator(){
        return adminService.getAvator();
    }

    /**
     * 更新头像
     * @param file
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = Result.class),
    })
    @ApiOperation("更新头像")
    @PostMapping("/updateAvator")
    public Result updateAvator(MultipartFile file){
        return adminService.updateAvator(file,myAvator);
    }

    /**
     * 获取文章数量
     * @return
     */
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = Result.class),
    })
    @ApiOperation("获取文章数量")
    @PostMapping("/articleCount")
    public Result articleCount(){
        return adminService.articleCount();
    }

}
